package com.ellecity06.cwhiskymall.ui.video

import android.os.Bundle
import android.view.View
import com.ellecity06.common.base.BaseMvvmActivity
import com.ellecity06.common.base.BaseViewModel
import com.ellecity06.common.utils.logD
import com.ellecity06.common.widgets.drag.DragBackLayout
import com.ellecity06.cwhiskymall.databinding.ActivityVideoPlayBinding
import com.shuyu.gsyvideoplayer.utils.GSYVideoType

/**
 * @author ellecity06
 * @time 2024/12/24 18:22
 * @des
 */
class PlayVideoActivity : BaseMvvmActivity<ActivityVideoPlayBinding, BaseViewModel>() {
    private val videoUrl: String? by lazy { intent.getStringExtra("video_url") }
    override val userBaseTitle: Boolean
        get() = false

    override fun inflateBinding(): ActivityVideoPlayBinding {
        return ActivityVideoPlayBinding.inflate(layoutInflater)
    }

    override fun onPostCreate(savedInstanceState: Bundle?) {
        super.onPostCreate(savedInstanceState)
        DragBackLayout(this).attachToActivity(this, object : DragBackLayout.Callback() {
            override fun onBack() {
                finish()
                overridePendingTransition(0, 0)
            }
        })
    }
    override fun initialize(savedInstanceState: Bundle?) {
        logD("视频播放url=$videoUrl")
        GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_DEFAULT)
        binding.videoView.backButton.visibility = View.GONE
        binding.videoView.fullscreenButton.visibility = View.GONE
        binding.videoView.setIsTouchWiget(false)
        binding.videoView.setUp(videoUrl, true, "")
        binding.videoView.startPlayLogic()
        binding.ivBack.setOnClickListener{
            onBackPressed()
        }
    }

    override fun onResume() {
        binding.videoView.onVideoResume()
        super.onResume()
    }

    override fun onPause() {
        binding.videoView.onVideoPause()
        super.onPause()
    }
    override fun onBackPressed() {
        //释放所有
        binding.videoView.setVideoAllCallBack(null)
        super.onBackPressed()

    }

    override fun onDestroy() {
        super.onDestroy()
        binding.videoView.release()
    }
    companion object {

    }
}